#include <stdio.h>

#define MAXLINE 1000 /* maximum input line length */

int getline  (char* line,   int max);
int strindex (char* source, char* searchfor);
char pattern[] = "the";                        /* pattern to search for */

/* find all lines matching pattern */
int main(int argc, const char** argv)
{
    char line[MAXLINE];
    int found = 0;
    while (getline(line, MAXLINE) > 0){
      if (strindex(line, pattern) >= 0) {
        printf("%s", line);
        ++found;
      }
    }
    return found;
}
/* getline: get line into line, return length */
int getline(char* line, int lim) {
    int c, i;
    i = 0;
    while (--lim > 0 && (c = getchar()) != EOF && c != '\n'){
      line[i++] = c;
      //      if (c == '\n'){
      //  line[i++] = c;
      //}
      }
    line[i] = '\0';
    return i;
}

/* strindex: return index of searchfor in line, -1 if none */
int strindex(char* line, char* searchfor) 
{
   int i;
   int j;
   int k;

   for (i = 0; line[i] != '\0'; i++) {
     for (j = i, k = 0; searchfor[k] != '\0' && line[j] == searchfor[k]; 
          j++, k++){
			;
      }
      if (k > 0 && searchfor[k] == '\0'){
        return i;
      }
    }
    return -1;
}
